<template>
  <div class="videoList">
    <div class="list" v-if="data.length>0 && listShow">
      <div class="item" v-for="(item,idx) in data" :style="{width:width+'px',height:height+'px'}" :key="item.id">
        <video :src="webCfg.api.url+':'+(webCfg.sixLines && idx/6>=1?'9000':webCfg.api.fileSvrPort)+'/'+item.url" autoplay controls loop
               style="width: 100%; height: 100%; object-fit: cover;" type="video/mp4" v-if="item.videoPath"></video>
        <img :src="item.imagePath" alt="" style="width: 100%; height: 100%; object-fit: cover;" v-else>
        <p class="state" v-show="item.state && item.state!=='正常'" v-if="item['type']==='camera'">
          <span class="send" @click="item['fn']">{{item.state}}</span>
        </p>
        <p class="state" v-if="item['type']==='event'">
          {{item.state}}
        </p>
      </div>
    </div>
    <div v-else style="color:#666; display: flex; align-items: center; justify-content: center" :style="{height:height*3+'px'}">
      查询结果为空！
    </div>
    <div class="page">
      <slot></slot>
    </div>
  </div>
</template>

<script>
  export default {
    name: "VideoList",
    components: {
    },
    props: ['data'],
    data() {
      return {
        webCfg:WebCfg,
        width: 0,
        height: 0,

        listShow:false
      }
    },
    mounted() {
      this.init();
    },
    watch:{
      data(n,o){
        this.listShow=false;
        this.$nextTick(()=>{
          this.listShow=true;
          const videos=document.querySelectorAll('video');
          if(videos.length>0){
            videos.forEach(video=>{
              video.currentTime=0.0;
              video.play();
            })
          }
        });

      }
    },
    methods: {
      init() {
        const W = window.screen.width;
        this.width = W / 4 ;
        this.height = W / 4 * 9 / 16 - 20 ;
      }
    },
    beforeDestroy() {
      const videos=document.querySelectorAll('video');
      if(videos.length>0){
        videos.forEach(video=>{
          video.currentTime=0.0;
          video.pause();

          video.setAttribute('src','');
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .videoList {
    display: flex;
    flex-direction: column;
    height: 100%;

    /deep/ .list {
      display: flex;
      flex-wrap: wrap;

      .item {
        border: 1px solid #000;
        box-sizing: border-box;
        position: relative;

        .name {
          position: absolute;
          bottom: 5px;
          left: 5px;
          text-align: center;
          font-size: 14px;
          font-weight: 600;
          text-shadow: -1px -1px 1px #333, 1px 1px 1px #999;
        }

        .state{
          position: absolute;
          top: 5px;
          right: 5px;
          text-align: center;
          font-size: 14px;
          font-weight: 600;
          color:#999;
          text-shadow: -1px -1px 1px #333, 1px 1px 1px #000;
        }

        .send{color:#369; cursor: pointer}
      }
    }

    .page {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
    }

    /deep/ .blackBg .el-pagination {
      .el-input__inner {
        background-color: #101010;
        border-color: rgba(255, 255, 255, .1);
        color: #006AA5;
        font-weight: 600;
      }

      .btn-next, .btn-prev {
        background: center center no-repeat #222;
        border: 1px solid #222;
        color: #555;
      }

      .btn-next:hover, .btn-prev:hover {
        color: var(--title-color)
      }

      button:disabled {
        color: #555 !important;
      }

      .el-pager li {
        background-color: #101010;
        border: 1px solid #111;
      }
    }
  }
</style>
